#include "StdAfx.h"
#include "GameMap.h"

CGameMap::~CGameMap(void)
{
	if (NULL != data_)
	{
		delete[] data_;
	}
}
void CGameMap::LoadMap(CArchive& ar)
{
	start_.SetPoint(0, 0);
	end_.SetPoint(0, 0);
	ar >> flag_;
	if (MAP_FILE_FLAG == flag_)
	{
		ar >> width_ >> height_;
		if (NULL != data_)
		{
			delete[] data_;
		}
		data_ = new unsigned char[width_ * height_];
		if (NULL != data_)
		{
			ar.Read(data_, width_ * height_);
			is_empty_ = false;

			finder_.SetMap(width_, height_, 
				boost::bind(&CGameMap::is_moveable, this, _1, _2), boost::bind(&CGameMap::get_move_cast, this, _1, _2));
		}
	}
}
void CGameMap::SaveMap(CArchive& ar)
{
	// ar << MAP_FILE_FLAG << width_ << height_;
}
void CGameMap::DrawMap(CDC* pDC)
{
	if (NULL == pDC)
		return;

	pDC->MoveTo(start_);
	for (std::vector<PathFinder::Point>::iterator it = path_.begin(); it != path_.end(); ++it)
	{
		pDC->LineTo(it->x, it->y);
		pDC->MoveTo(it->x, it->y);
	}
}
PathFinder::FindResult CGameMap::FindPath()
{
//	return finder_.FindPath(PathFinder::Point(start_.x, start_.y), PathFinder::Point(end_.x, end_.y), path_);


	return PathFinder::FIND_SUCCESS;
}